﻿using System.Collections.Generic;
using System.Linq;
using Algoritmia.StateSpaces;
using Lists = Algoritmia.DataStructures.Lists;

namespace Algoritmia.Problems.GeneralizedCoinChange.ByScheme
{
    public class MoneyChangeForwardStateSpace : IForwardStateSpace<int,int>
    {
        private int _Q;
        private readonly Lists.IList<int> _values;

        public MoneyChangeForwardStateSpace(int Q, Lists.IList<int> values)
        {
            _Q = Q;
            _values = values;
        }

        #region Implementation of IForwardStateSpace<int,int>

        public int Decide(int state, int decision)
        {
            return state + decision;
        }

        public IEnumerable<int> Decisions(int state)
        {
            return _values.Where(value => value + state <= _Q);
        }

        public IEnumerable<int> InitialStates
        {
            get { yield return 0; }
        }

        public bool IsFinal(int state)
        {
            return _Q == state;
        }

        #endregion
    }
}
